﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoolCode.Entities;
using CoolCode.Linq;
using CoolCode.Web.UI;

namespace CoolCode.Web.UI.Controls
{
    public partial class SearchList : Partial<PaginatedList<SearchItem>>, IPager
    {
        public bool AutoLoad { get; set; }

        public event GridViewPageEventHandler PageIndexChanging;

        public SearchList()
        {
            AutoLoad = true;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            handleEvents();
        }

        protected void handleEvents()
        { 
            pgrMaster.PageIndexChanging += PageIndexChanging;            
        }

        protected override void OnPreRender(EventArgs e)
        {
            if (AutoLoad)
            {
                if (!Page.IsPostBack)
                {
                    if (PageIndexChanging != null)
                    {
                        PageIndexChanging(this, new GridViewPageEventArgs(0));
                    }
                }
            }
            else
            {
                pgrMaster.Visible = false;
            }
            base.OnPreRender(e);
        }

        public override void DataBind()
        {
            pgrMaster.Bind(Model); 
        }
 
    }
}